package factory;

import factory.excutor.DefaultExcutor;
import factory.jdbc.JdbcFactory;
import factory.proxy.MapperProxyFactory;

import java.sql.Connection;


public class SqlSession {
    private Configuration configuration;


    private DefaultExcutor excutor;

    public SqlSession(Configuration configuration) {
        this.configuration = configuration;
        this.excutor = new DefaultExcutor(configuration.getDatabaseInfo());
    }

    public <T> T getMapper (Class<T> type) {
        return (T) new MapperProxyFactory(type, configuration, excutor).getProxy();
    }

    public Connection getCon () {
        return JdbcFactory.getConnection(configuration.getDatabaseInfo());
    }
}
